package com.sinszm.web.exception;

import com.sinszm.common.Response;
import com.sinszm.common.exception.ApiException;
import com.sinszm.common.exception.SystemApiError;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 统一错误页
 *
 * @author chenjianbo
 */
@RestController
public class GlobalErrorPager {

    @RequestMapping(value = "/szm/err_{code}", produces = MediaType.APPLICATION_JSON_VALUE)
    public Response<Object> error(@PathVariable String code, @RequestParam(required = false) String message) {
        ApiException exception = new ApiException(
                SystemApiError.SYSTEM_ERROR_01.getCode(),
                StringUtils.isEmpty(message) ? code : message
        );
        return Response.fail(exception.apiError(), exception);
    }

}
